/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightAdjustHotel;
import com.sasis.dao.FlightAdjustHotelDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightAdjustHotelDaoiBatis extends BaseDaoiBATIS implements FlightAdjustHotelDao {

    /**
     * @see com.sasis.dao.FlightAdjustHotelDao#getFlightAdjustHotels(com.sasis.model.FlightAdjustHotel)
     */
    public List getFlightAdjustHotels(final FlightAdjustHotel flightAdjustHotel) {
          return getSqlMapClientTemplate().queryForList("getFlightAdjustHotels", flightAdjustHotel);
    }

    /**
     * @see com.sasis.dao.FlightAdjustHotelDao#getFlightAdjustHotel(Integer id)
     */
    public FlightAdjustHotel getFlightAdjustHotel(Integer id) {
        FlightAdjustHotel flightAdjustHotel = (FlightAdjustHotel) getSqlMapClientTemplate().queryForObject("getFlightAdjustHotel", id);

        //if (flightAdjustHotel == null) {
            //throw new ObjectRetrievalFailureException(FlightAdjustHotel.class, id);
        //}

        return flightAdjustHotel;
    }

    /**
     * @see com.sasis.dao.FlightAdjustHotelDao#saveFlightAdjustHotel(FlightAdjustHotel flightAdjustHotel)
     */    
    public int saveFlightAdjustHotel(final FlightAdjustHotel flightAdjustHotel) {
        Integer id = flightAdjustHotel.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightAdjustHotel", flightAdjustHotel);
        } else {
            getSqlMapClientTemplate().update("updateFlightAdjustHotel", flightAdjustHotel);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightAdjustHotel.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightAdjustHotelDao#removeFlightAdjustHotel(Integer id)
     */
    public void removeFlightAdjustHotel(FlightAdjustHotel flightAdjustHotel) {
        getSqlMapClientTemplate().update("deleteFlightAdjustHotel",  flightAdjustHotel);
    }
    
    public void deleteFlightAdjustHotel(FlightAdjustHotel flightAdjustHotel){
    	 getSqlMapClientTemplate().update("deleteHotelByFlightInfoId",  flightAdjustHotel);
    }
}
